package com.tangye.massageshop.controller;

import com.alibaba.fastjson.JSON;
import com.tangye.massageshop.entity.ShopEntity;
import com.tangye.massageshop.entity.UserEntity;
import com.tangye.massageshop.service.ShopService;
import com.tangye.massageshop.util.Result;
import com.tangye.massageshop.util.ThreadLocalUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Log4j2
@RestController
@RequestMapping("/shop")
public class ShopController {
    
    @Resource
    private ShopService shopService;

    @PostMapping("/queryShopPage")
    public Result<List<ShopEntity>> queryShopPage(ShopEntity shop) {
        log.info("入参：{}",JSON.toJSONString(shop));
        UserEntity userSession = ThreadLocalUtil.get();
        shop.setCompanyId(userSession.getCompanyId());
        shop.setShopId(userSession.getShopId());
        List<ShopEntity> shopEntities = shopService.queryShopListPage(shop);
        log.info("反参：{}",JSON.toJSONString(shopEntities));
        return Result.success(shopEntities);
    }

    @PostMapping("/addShop")
    public Result<UserEntity> addShop(@Validated ShopEntity shop) {
        log.info("入参：{}",JSON.toJSONString(shop));
        UserEntity userSession = ThreadLocalUtil.get();
        shop.setCompanyId(userSession.getCompanyId());
        UserEntity userEntity = shopService.add(shop);
        log.info("反参：{}",JSON.toJSONString(userEntity));
        return Result.success(userEntity);
    }

    @PostMapping("/updateShop")
    public Result<String> updateShop(@Validated ShopEntity shop) {
        shopService.updateShop(shop);
        return Result.ok();
    }




}
